﻿#include "ssClockSolt.h"


namespace StarSeeker
{

ssClockSolt::ssClockSolt()
{
}

ssClockSolt::~ssClockSolt()
{
}

void ssClockSolt::Push(ssTimer_s& msg)
{
	std::map<u32, std::list<ssTimer_s> >::iterator itr = m_msgList.find((u32)msg.timestamp);
	if (itr==m_msgList.end())
	{
		std::list<ssTimer_s> list;
		list.push_back(msg);
		m_msgList[(u32)msg.timestamp] = list;
	} 
	else
	{
		itr->second.push_back(msg);
	}
}

std::list<StarSeeker::ssTimer_s>* ssClockSolt::GetList(u32 tick)
{
	std::map<u32, std::list<ssTimer_s> >::iterator itr = m_msgList.find(tick);
	if (itr != m_msgList.end())
	{
		return &itr->second;
	}
	return 0;
}

bool ssClockSolt::Delete(u32 id)
{
	if (!m_msgList.empty())
	{
		for (std::map<u32, std::list<ssTimer_s> >::iterator itr = m_msgList.begin(); itr != m_msgList.end(); ++itr)
		{
			if (!itr->second.empty())
			{
				for (std::list<ssTimer_s>::iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2)
				{
					if (itr2->subID==id)
					{
						itr->second.erase(itr2);
						return true;
					}
				}
			}
		}
	}
	return false;
}

}
